<?php if(!defined('SPRITCH')) { exit(); }

// Spritch - An opensource PHP5 web framework

// Author: Luca Degasperi
// Licence: GNU GPL
// Site: http://www.spritch.org/

// Class: Configuration
// Summary: This class provides access to the configuration files
// Since: 0.9.1

class configuration extends spritch
{
	private $config = array();
	
	public function __construct()
	{
		$this->profiler->log('configuration class started');
	}
	
	public function get($key,$default = null)
	{
		if(empty($this->config['default']))
		{
			$path = $this->exists('configuration','configuration');
			if($path)
			{	
				include_once($path);
				$this->config['default'] = $config;
			}
			else
			{
				$this->profiler->warning('configuration file missing');
			}
		}
		if(array_key_exists($key,$this->config['default']))
			return $this->config['default'][$key];
		else
			if(!is_null($default))
				return $default;
		return false;
	}
	
	public function __call($method,$args = array())
	{
		if(empty($this->config[$method]))
		{
			$path = $this->exists($method,'configuration');
			if($path)
			{
				include_once($path);
				$this->config[$method] = $config;
			}
			else
			{
				$this->config[$method] = array();
			}
		}
		if(array_key_exists($args[0],$this->config[$method]))
			return $this->config[$method][$args[0]];
		else
			if(!is_null($args[1]))
				return $args[1];
		return false;
	}
}
?>